<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">用户管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
      <el-breadcrumb-item>用户详情</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表格 -->
    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="id" label="名称" width="180">
        <template slot-scope="scope"> {{ scope.row.id }} </template>
      </el-table-column>

      <el-table-column prop="name" label="姓名" width="180">
        <template slot-scope="scope"> {{ scope.row.name }} </template>
      </el-table-column>
      <el-table-column prop="age" label="年龄">
        <template slot-scope="scope"> {{ scope.row.age }} </template>
      </el-table-column>
      <el-table-column prop="gender" label="性别">
        <template slot-scope="scope">
          {{ scope.row.gender == "m" ? "男性" : "女性" }}
        </template>
      </el-table-column>
      <el-table-column prop="gender" label="婚姻状况">
        <!-- 自定义列模板 -->
        <template slot-scope="scope">
          <el-tag v-if="scope.row.married" type="success">已婚</el-tag>
          <el-tag v-else type="danger">未婚</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle></el-button>
          <!-- scope.$index 传下标过去 -->
          <el-button
            @click="deleteRow(scope.$index)"
            type="danger"
            icon="el-icon-delete"
            circle
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        { id: 1, name: "凉凉", age: 38, gender: "m", married: true },
        { id: 2, name: "泡泡", age: 18, gender: "f", married: false },
        { id: 3, name: "小新", age: 28, gender: "m", married: true },
        { id: 4, name: "华哥", age: 40, gender: "m", married: true },
      ],
    };
  },
  methods: {
    /* 接受传过来的scope.$index */
    deleteRow(idx) {
      console.log("正在删除" + idx);
      /* 应用tableData方法  */
      this.tableData.splice(idx, 1);
      /* 弹框内容 */
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
